<script setup>
import start from "../../store/index";
import {ref ,reactive} from 'vue'

const tableData=ref([
  {
    name: '2016-05-03',
    phone: 'Tom',
    address: 'No. 189, Grove St, Los Angeles',
  },
  {
    name: '2016-05-02',
    phone: 'Tom',
    address: 'No. 189, Grove St, Los Angeles',
  },
  {
    name: '2016-05-04',
    phone: 'Tom',
    address: 'No. 189, Grove St, Los Angeles',
  },
  {
    name: '2016-05-01',
    phone: 'Tom',
    address: 'No. 189, Grove St, Los Angeles',
  },
  {
    name: '2016-05-08',
    phone: 'Tom',
    address: 'No. 189, Grove St, Los Angeles',
  }
])

// 分页
const pageSize4 = ref(1)
const currentPage4 = ref(1)
const handleSizeChange = () => {
  
}
const handleCurrentChange = ()=> {

}

// 新增表单
const form = ref({
  name:'',
  phone:'',
  address:''
})
const formRef=ref({})

// 弹窗
const dialogVisible = ref(false)
const handleClose = () => {
 
}
const onDelete=()=>{
  dialogVisible.value=!dialogVisible.value
}

// 表单弹窗
const showForm = ref(false)

// 表单验证
const rules = reactive({
  address: [
    {
      required: true,
      message: '信息不能为空',
      trigger: 'blur',
    },
  ],
  name: [
    {
      required: true,
      message: '信息不能为空',
      trigger: 'blur',
    }
  ],
   phone: [
    {
      required: true,
      message: '信息不能为空',
      trigger: 'blur',
    }
  ]
})

// 新增
const onAdd=()=>{
  showForm.value=!showForm.value
}
</script>

<template>
  <el-button type="primary" @click="onAdd">新增</el-button>
  <el-button type="success">修改</el-button>
  <el-button type="info">批量删除</el-button>

  <!-- 表格 -->
   <el-table
    ref="multipleTableRef"
    :data="tableData"
    style="width: 100%; margin-top:10px"
  >
    <el-table-column type="selection" width="55" />
    <el-table-column label="校区名称" width="180">
      <template #default="scope">{{ scope.row.name }}</template>
    </el-table-column>
    <el-table-column property="address" label="地址" width="320" />
    <el-table-column property="phone" label="电话" show-overflow-tooltip />
    <el-table-column label="操作" width="220">
      <el-button type="success">编辑</el-button>
      <el-button type="info" @click="onDelete">删除</el-button>
    </el-table-column>
  </el-table>

  <!-- 分页 -->
  <el-pagination
    style="margin-top: 10px;"
    v-model:currentPage="currentPage4"
    v-model:page-size="pageSize4"
    :page-sizes="[100, 200, 300, 400]"
    layout="total, sizes, prev, pager, next, jumper"
    :total="400"
    @size-change="handleSizeChange"
    @current-change="handleCurrentChange"
  >
  </el-pagination>

  <!-- 弹窗 -->
  <el-dialog
    v-model="dialogVisible"
    title="删除"
    width="30%"
    :before-close="handleClose"
  >
    <span>确定要删除数据?</span>
    <template #footer>
      <span class="dialog-footer">
        <el-button @click="dialogVisible = false">取消</el-button>
        <el-button type="primary" @click="dialogVisible = false">确认</el-button>
      </span>
    </template>
  </el-dialog>

  <!-- form表单 -->
 <el-dialog
    v-model="showForm"
    title="新增数据"
    width="50%"
  >
    <el-form ref="formRef" :model="form" :rules="rules" label-width="120px">
      <el-form-item label="校区名称" prop="name">
        <el-input v-model="form.name"></el-input>
      </el-form-item>
       <el-form-item label="地址" prop="address">
        <el-input v-model="form.address"></el-input>
      </el-form-item>
       <el-form-item label="电话" prop="phone">
        <el-input v-model="form.phone"></el-input>
      </el-form-item>
    </el-form>
    <template #footer>
      <span class="dialog-footer">
        <el-button>取消</el-button>
        <el-button type="primary">确认</el-button>
      </span>
    </template>
  </el-dialog>


</template>

<style>
*{
  padding: 0;
  margin: 0;
}
</style>
